package follow.juc.heima.day9;

import java.util.HashMap;
import java.util.Map;

/**
 * 业务操作的线程安全不能保证
 */
public class Demo4ConcurrentHashMap2 {
    public static void main(String[] args) {
        final Map<String, Integer> count = new HashMap<>();
        //new ConcurrentHashMap<>();
        count.put("count",0);

        Runnable task = new Runnable(){

            @Override
            public void run() {
                int value;
                for (int i=0;i<2000;i++){
                    value=count.get("count");
                    count.put("count",value+1);
                }

            }
        };

        new Thread(task).start();
        new Thread(task).start();
        new Thread(task).start();

        try {
            Thread.sleep(10001);
            System.out.println(count);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    } 

}
